#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define DEBUG 1
int main() {
    auto f1 = [](pair<int, int> p1, pair<int, int> p2) {
        if (p1.first == p2.first)
        {
            return p1.second < p2.second;
        }
        else {
            return p1.first < p2.first;
        }
        };
    vector<pair<int, int>> v;
    int num = 0;
    cin >> num;
    while (num--)
    {
        pair<int, int> p;
        cin >> p.first >> p.second;
        v.push_back(p);
    }
    sort(v.begin(), v.end(), f1);
#ifdef DEBUG
    for (auto i : v)
    {
        cout << i.first << ' ' << i.second << endl;
    }
#endif
    int x, y;
    x = v[0].first;
    y = v[0].second;
    int Max = 1;
    for (int i = 1; i < v.size(); i++)
    {
        if (v[i].first == x)
        {
            continue;
        }
        else {
            if (v[i].first >= y)
            {
                x = v[i].first;
                y = v[i].second;
                Max++;
            }
        }
    }

    cout << Max;

    return 0;
}



//bool Com(pair<int,int>a,pair<int,int>b)
//{
//	return a.first > b.first;
//}
//struct Compare
//{
//	bool operator()(pair<int, int>a, pair<int, int>b)
//	{
//		return a.first > b.first;
//	}
//};
//int main()
//{
//	vector<int> v = { 1,2,3,4,5 };
//	map<int, int, decltype(Com)> mp(Com);
//	//map<int, int,Compare> mp;
//
//
//	return 0;
//}